// 采购列表
import React from 'react'
import './deviceBuy.scss'
import AreaData from "../../../component/areaData/areaData"
import utils from '../../../utils/utils'
import cookie from 'react-cookies'
import moment from 'moment'
import { Space, Tabs, Row, Col,Select,DatePicker,Table,Button,Input,Card,Image,Descriptions,Switch } from 'antd';
import BreadcrumbNav from '../../../component/breadcrumb/breadcrumb'
import { EditOutlined, DeleteOutlined ,SettingOutlined,LoadingOutlined, PlusOutlined ,UploadOutlined} from '@ant-design/icons';
import {eqBuyInfoList} from '../../../api/deviceLibrary'

const { Column } = Table;
class deviceBuy extends React.Component{
    state = {
        buy_info_list:[]
    }
    componentWillMount(){
		this.columns = [
			{
				title: '采购编号',
				dataIndex: 'number',
				key: 'number',
			},
			{
				title: '合同名称',
				dataIndex: 'contract_name',
				key: 'contract_name',
			},
			{
				title: '合同金额',
				key: 'contract_amount',
				dataIndex: 'contract_amount',
			},
			{
				title: '采购设备',
				dataIndex: 'eq_name',
				key: 'eq_name',
			},
			{
				title: '采买人',
				dataIndex: 'buy_u_name',
				key: 'buy_u_name',
			},
			{
				title: '合同时间',
				key: 'contract_time',
				dataIndex: 'contract_time'
			},
			{
			  title: '操作',
			  key: 'action',
			  render: (text, record) => {
				return <Space size="middle">
					<span style={{ marginRight:'6px', color:'#2F3CF2', cursor:'pointer'}} className="link" onClick={this.toDetail.bind(this,text.id)}>查看详情</span>
				</Space>
			  },
			},
		];
    }
    componentDidMount(){
         this.geteqBuyInfoList()
    }
    // 获取数据
	geteqBuyInfoList = () => {
		let post_data = {
            auth_token:cookie.load('station_console_setting_web_login').auth_token,
        }
		eqBuyInfoList(post_data).then( res => {
			this.setState({
				buy_info_list:res.data.buy_info_list
			})
		})
	}

    // 查看详情
    toDetail = (id) => {
        this.props.history.push({ pathname:`/index/deviceLibrary/deviceBuy/buyDetail`, state:{id}})
    }

    // 采购录入
    toAdd = () => {
		this.props.history.push('/index/deviceLibrary/deviceBuy/addNewDevice')
    }

    render(){
        const {buy_info_list} = this.state
        return (
            <div id="ContentMainList" className="deviceBuy">
                <Row>
                    <Col span={24}>
                        <BreadcrumbNav />
                    </Col>
                    <Col span={24}>
                        <div className="tipss">
                            <span className="blue"></span>
                            <span>设备基本信息</span>
                            <Button onClick={this.toAdd.bind(this)} type='primary' style={{color:'#fff',float:'right',marginRight:'40px',borderRadius:'10px',}}>
                                + 采购录入
                            </Button>
                        </div>
                    </Col>
                    <Col span={24}>
                        <Table dataSource={buy_info_list}  columns={this.columns} pagination={false} locale={{ emptyText: '暂无数据' }} style={{width:'100%'}}></Table>
                    </Col>
                </Row>
            </div>
        )
    }
}

export default deviceBuy